package io.seata.order.controller;


import io.seata.order.entity.Order;
import io.seata.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/seata/test")
    public ResponseEntity<Void> seataDemo(@RequestParam(value="hasError", required=false) Boolean hasError){
        orderService.seataDemo(hasError);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    @GetMapping("/seata/listall")
    public List<Order> seataListAll(){
        List<Order> list = orderService.listAll();
        return list;
    }


    /**
     * 条件查询，如果查询条件中分库分库分表键被设置为null，就会报错
     * @param query
     * @return
     */
    @PostMapping("/seata/byCondition")
    public List<Order> selectByCondition(@RequestBody Order query){
        List<Order> list = orderService.selectByConditon(query);
        return list;
    }

    /**
     * 分页查询
     * @return
     */
    @PostMapping("/seata/page")
    public List<Order> seataListPage(){
        List<Order> list = orderService.listAll();
        return list;
    }
}
